<?php
class Training_RelationshipController extends Zendvn_Controller_Action{
	
	//Tham so 
	protected $_arrParam;
	
	public function init(){
		$this->_arrParam = $this->_request->getParams();
	}
	
	//6. many to many
	public function index6Action(){
		$tblCat = new Shop_Model_NewsCategory();
		$rowSet = $tblCat->find(1); //create rowSet
		$rowA = $rowSet->current();
		
		//$result = $rowA->findManyToManyRowset('Shop_Model_NewsArticle', 'Shop_Model_ArticleCategory');
		//$result = $rowA->findManyToManyRowset('Shop_Model_NewsArticle', 'Shop_Model_ArticleCategory');
		$result = $rowA->findShop_Model_NewsArticleViaShop_Model_ArticleCategory();
		echo '<pre>';
		print_r($result->toArray());
		echo '</pre>';
		
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	//5. child to parent
	public function index5Action(){
		$tblUser = new Shop_Model_User();
		$rowSet = $tblUser->find(3); //create rowSet
		$rowA = $rowSet->current();
		$select = $tblUser->select()
						 ->from('user_group',array('id','name'));
		//$result = $rowA->findParentRow('Shop_Model_UserGroup','GroupMap',$select);
		$result = $rowA->findParentShop_Model_UserGroupByGroupMap($select);
		
		echo '<pre>';
		print_r($result);
		echo '</pre>';
		
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	//4. child to parent
	public function index4Action(){
		$tblUser = new Shop_Model_User();
		$rowSet = $tblUser->find(3); //create rowSet
		$rowA = $rowSet->current();
		$select = $tblUser->select()
						 ->from('user_group',array('id','name'));
		$result = $rowA->findParentRow('Shop_Model_UserGroup','GroupMap',$select);
		echo '<pre>';
		print_r($result);
		echo '</pre>';
		
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	//3. parent to child
	public function index3Action(){
		$tblGroup = new Shop_Model_UserGroup();
		$rowSet = $tblGroup->find(44); //create rowSet
		$rowA = $rowSet->current();
		$rowA->delete();
		
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	//2. parent to child
	public function index2Action(){
		$tblGroup = new Shop_Model_UserGroup();
		$rowSet = $tblGroup->find(4); //create rowSet
		$row4 = $rowSet->current();
		
		$select = $tblGroup->select()->where('status = 0');
		
		//$result = $row4->findDependentRowset('Shop_Model_User','GroupMap',$select);
		$result = $row4->findShop_Model_UserByGroupMap($select);
		echo '<pre>';
		print_r($result->toArray());
		echo '</pre>';
		
		$this->_helper->viewRenderer->setNoRender();
	}
	
	//1. parent to child
	public function indexAction(){
		$tblGroup = new Shop_Model_UserGroup();
		$rowSet = $tblGroup->find(4); //create rowSet
		$row4 = $rowSet->current();
		
		$select = $tblGroup->select()->where('status = 0');
		
		$result = $row4->findDependentRowset('Shop_Model_User','GroupMap',$select);
		echo '<pre>';
		print_r($result->toArray());
		echo '</pre>';
		
		$this->_helper->viewRenderer->setNoRender();
	}
	

	
	
}